package LeetCode.LeetCode2;

/**
 * 二分查找
 * @author lumin
 * @date 2022/03/16 20:25
 **/
public class Num704 {
    public static int search(int[] nums, int target) {
        if(nums.length == 0){
            return -1;
        }
        int left = 0;
        int right = nums.length - 1;
        while(left <= right){
            int mid = (left + right) >> 1;
            if(nums[mid] > target) {
                right = mid - 1;
            }else if(nums[mid] < target){
                left = mid + 1;
            }else if(nums[mid] == target){
                return mid;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr = {2,5};
        System.out.println(search(arr,5));
    }
}